<template>
  <div class="my-tag">
    <input class="input" v-if="flag"  type="text" placeholder="输入标签" 
    :value="value" @blur="close" @keyup.enter="$event.target.blur()" v-focus/>
    <div class="text" v-else @dblclick="flag=!flag">{{value}}</div>
  </div>
</template>

<script>
export default {
  name:"MyTag",
  data() {
    return {
      flag:false
    };
  },
  props:{
    value:{
      type:String,
      required:true
    }
  },
  methods:{
   close(e){
    if(e.target.value.trim().length<=0){
      alert('输入不能为空')
    }else{
      this.$emit('input',e.target.value)
    }
      this.flag=false
      console.log(2342)
    }
  }
};
</script>

<style scoped lang="less">
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>
